package com.visionblue.business.ship

import android.app.Application
import android.content.Context
import com.facebook.stetho.Stetho
import com.tencent.bugly.Bugly
import com.tencent.bugly.beta.Beta
import com.visionblue.business.ship.di.appModule
import com.visionblue.business.ship.model.repository.DeviceInfoRepository
import com.visionblue.business.ship.page.MainActivity
import com.visionblue.business.ship.util.MLog
import org.koin.android.ext.android.get
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin
import kotlin.properties.Delegates


/**
 * @author: xlh
 * @date: 2020-04-10 2:10 PM
 * @desc:
 */
class App : Application() {

    lateinit var deviceInfoRepository: DeviceInfoRepository

    override fun onCreate() {
        super.onCreate()
        context = applicationContext

        startKoin {
            androidContext(this@App)
            modules(appModule)
        }

        deviceInfoRepository = get()

        if (!BuildConfig.LOG_DEBUG) {
            MLog.setNoLog()
        }

        Stetho.initializeWithDefaults(this)

        initBugly()

    }

    private fun initBugly() {

        Beta.canShowUpgradeActs.add(MainActivity::class.java)

        Beta.upgradeDialogLayoutId = R.layout.upgrade_dialog

        /**
         * 参数解析：

        参数1：上下文对象

        参数2：注册时申请的APPID

        参数3：是否开启debug模式，true表示打开debug模式，false表示关闭调试模式
         */
        Bugly.init(context,"bd4194c13e",false)
        //CrashReport.initCrashReport(applicationContext, "bd4194c13e", true)异常上报，我的
        // CrashReport.initCrashReport(applicationContext, "586e3048a1", false)原来

    }


    companion object {
        var context: Context by Delegates.notNull()

    }
}